<?php

namespace App\Http\Controllers\Admin;

use App\Http\Query\CategoryQuery;
use app\Model\Base;
use app\Model\OrderModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Log;
use function MongoDB\BSON\toJSON;
use SplFileObject;

class JapanBillController extends Controller

{

    function bill_list(Request $request)
    {
        $getParam = $request->all();
        $map = [];

        if (!empty($getParam['corp_id'])) {
            $map['cm.corp_id'] = $getParam['corp_id'];
        }
        if (!empty($getParam['send_state'])) {
            $map['uo.send_state'] = $getParam['send_state'];
        }
        $list = DB::table('user_order as uo')
            ->select(DB::raw('uo.create_time,uo.send_state,cm.corp_name,uo.actual_money,uo.name,uo.add,uo.order_id'))
            ->leftJoin('user_master as um', 'uo.user_id', '=', 'um.user_id')
            ->leftJoin('corp_master as cm', 'cm.corp_id', '=', 'um.corp_id')
            ->where($map)->get();

        foreach ($list as $key => $value) {
            $list[$key]->goods_num = DB::table('user_order_detailed')
                ->where('order_id', '=', $value->order_id)
                ->sum('goods_num');
        }
        $mo = new \App\Model\Base();
        return view('warehouse.bill', array(
            'companys' => $mo::companys(),
            'category' => $mo::category(),
            'param' => $getParam,
            'list' => $list,
        )); // 返回视图

    }
}
